package com.haidechizi.leetcode;

/**
 * @author: wangdejun
 * @create: 2020-04-02 11:06
 **/
public class _4_二维数组中的查找 {


    /**
     * 从右上角开始查找
     * 小于i++
     * 大于j--
     *
     * @param matrix
     * @param target
     * @return
     */
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if(matrix == null || matrix.length == 0) {
            return false;
        }
        int i = 0;
        int j = matrix[i].length - 1;
        while (i < matrix.length && j >= 0) {
            if (matrix[i][j] == target) {
                return true;
            } else if (matrix[i][j] > target) {
                j--;
            } else {
                i++;
            }
        }
        return false;

    }
}
